/*
 * Inspiration from http://www.antonioshome.net/kitchen/swingnbrcp/swingnbrcp-nodes1.php
 */
package org.tintuna.cca.node;

import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Sheet;
import org.openide.util.lookup.AbstractLookup;
import org.openide.util.lookup.InstanceContent;
import org.openide.util.lookup.ProxyLookup;
import org.tintuna.cca.data.Row;
import org.tintuna.cca.property.AmountProperty;
import org.tintuna.cca.property.BalanceProperty;
import org.tintuna.cca.property.CategoryProperty;
import org.tintuna.cca.property.DateProperty;
import org.tintuna.cca.property.MerchantProperty;
import org.tintuna.cca.property.TransactionProperty;

/**
 *
 * @author bsmith
 */
public class RowNode extends AbstractNode {

    private Row row;
    private InstanceContent instanceContent;
    public static final String DATE_PROPERTY = "Date Property";
    public static final String AMOUNT_PROPERTY = "Amount";
    public static final String TRANS_PROPERTY = "TransactionType";
    public static final String MERCHANT_PROPERTY = "Merchant";
    public static final String BALANCE_PROPERTY = "Balance";
    public static final String CATEGORIES_PROPERTY = "Categories";

    public RowNode(Row row) {
        this(row, new InstanceContent());
    }

    public RowNode(Row row, InstanceContent instanceContent) {
        super(Children.LEAF, new ProxyLookup(row.getLookup(), new AbstractLookup(instanceContent)));
        this.row = row;
        this.instanceContent = instanceContent;
        this.instanceContent.add(row);
        // Add abilities to the  node in this instanceContent
        // this.instanceContent.add( new WhateverAbility() );
    }

//    @Override
//    public String getDisplayName() {
//        return row.getName();
//    }
    /**
     * This method is invoked once to create a Sheet of Properties of this node.
     * @return A Sheet of Properties for this node.
     */
    @Override
    protected Sheet createSheet() {
        Sheet sheet = Sheet.createDefault();
        Sheet.Set set = Sheet.createPropertiesSet();

        DateProperty dateProperty = new DateProperty(row);
        AmountProperty amountProperty = new AmountProperty(row);
        TransactionProperty transactionProperty = new TransactionProperty(row);
        MerchantProperty merchantProperty = new MerchantProperty(row);
        BalanceProperty balanceProperty = new BalanceProperty(row);
        CategoryProperty categoryProperty = new CategoryProperty(row);
        
        set.put(dateProperty);
        set.put(amountProperty);
        set.put(transactionProperty);
        set.put(merchantProperty);
        set.put(balanceProperty);
        set.put(categoryProperty);
        
        sheet.put(set);

        return sheet;
    }
}
